package com.ala4.oxcafe.entity;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.ala4.oxcafe.boot.annotation.ExcelIntToStr;
import com.ala4.oxcafe.boot.converter.ExcelIntToStrConverter;
import com.ala4.oxcafe.core.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 服务单主表实体
 *
 * @author PING
 * @version 1.0.0
 * @date 2025/8/15 11:55
 */
@Data
@ExcelIgnoreUnannotated
@EqualsAndHashCode(callSuper = true)
@TableName("service_order")  // 实际表名
@Schema(description = "服务单主表实体")
public class ServiceOrder extends BaseEntity {

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @Schema(description = "服务单ID")
    @NotNull(message = "ID不能为空", groups = {Update.class})
    private Long id;

    @Schema(description = "服务单号")
    @NotNull(message = "服务单号不能为空", groups = {Update.class})
    @ExcelProperty("服务单号")
    private String serviceNo;

    @TableField("customer_name")
    @Schema(description = "客户名称")
    @NotNull(message = "客户名称不能为空", groups = {Create.class, Update.class})
    @NotEmpty(message = "客户名称不能为空", groups = {Create.class, Update.class})
    @ExcelProperty("客户名称")
    private String customerName;

    @TableField("customer_phone")
    @Schema(description = "手机号")
    @NotNull(message = "手机号不能为空", groups = {Create.class, Update.class})
    @NotEmpty(message = "手机号不能为空", groups = {Create.class, Update.class})
    @ExcelProperty("手机号")
    private String customerPhone;

    @Schema(description = "服务门店Id")
//    @NotNull(message = "服务门店不能为空", groups = {Create.class, Update.class})
    private Long storeId;
    @Schema(description = "服务门店编码")
    private String storeCode;
    @Schema(description = "服务门店名称")
    private String storeName;

    @TableField("car_plate")
    @Schema(description = "车牌号")
    @NotNull(message = "车牌号不能为空", groups = {Create.class, Update.class})
    @NotEmpty(message = "车牌号不能为空", groups = {Create.class, Update.class})
    @ExcelProperty("车牌号")
    private String carPlate;

    @TableField("car_vin")
    @Schema(description = "车架号")
    @ExcelProperty("车架号")
    private String carVin;

    @TableField("car_model")
    @Schema(description = "车辆型号")
    @ExcelProperty("车辆型号")
    private String carModel;

    @TableField("car_color")
    @Schema(description = "车辆颜色")
    @ExcelProperty("车辆颜色")
    private String carColor;

    @TableField("service_date")
    @Schema(description = "施工日期")
    @NotNull(message = "施工日期不能为空", groups = {Create.class, Update.class})
    @ExcelProperty("施工日期")
    private LocalDateTime serviceDate;

    @TableField("operator")
    @Schema(description = "施工人")
    @NotNull(message = "施工人不能为空", groups = {Create.class, Update.class})
    @NotEmpty(message = "施工人不能为空", groups = {Create.class, Update.class})
    @ExcelProperty("施工人")
    private String operator;

    @TableField("status")
    @Schema(description = "服务单状态(0待审核,1已审核,2已驳回)")
    @ExcelIntToStr("0=待审核,1=已审核,2=已驳回")
    @ExcelProperty(value = "服务单状态", converter = ExcelIntToStrConverter.class)
    private Integer status;

    @Schema(description = "审核意见")
    @TableField("audit_comments")
    private String auditComments;
    @NotNull(message = "施工产品产品不能为空", groups = {Create.class, Update.class})
    @NotEmpty(message = "施工产品产品不能为空", groups = {Create.class, Update.class})
    @TableField(exist = false)
    private List<ServiceOrderDetail> serviceOrderDetails;

    public interface Create {

    }

    public interface Update {

    }

}
